package com.activitycode.view;



import java.util.ArrayList;
import java.util.List;

import com.activitycode.util.BaseTask;
import com.activitycode.util.ScreenManager;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;


public class BaseFragment extends Fragment{
	public String tag = "BaseFragment";
	protected List<BaseTask> taskList = new ArrayList<BaseTask>();
	
	protected Activity activity;
	@Override
	public void onAttach(Activity activity){
		super.onAttach(activity);
		this.activity = activity;
		
	}
	
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState); 
	}
	
	@Override
	public void onPause(){
		super.onPause();
	}
	
	@Override
	public void onResume(){
		super.onResume();
	}
	
	@Override
	public void onDestroy(){
		super.onDestroy();
		cancelTasks();
	}
	
	protected void addTask(BaseTask task){
		try {
			taskList.add(task);
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}		
	}
	
	protected void cancelTasks(){
		for(int i=0;i<taskList.size();i++){
		try {			
			BaseTask task = taskList.get(i);
			if(task!=null&&!task.isCancelled()){
				task.cancelTasks();
			}			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		}
	}


	
	
	
}